<template>
  <div>
    <el-form :inline="true">
      <el-form-item>
        <el-input
          v-model="params.phone_number"
          placeholder="电话号码"
          @keyup.enter.native="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.user_name"
          placeholder="账号名称"
          @keyup.enter.native="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getData()" class="btn-long" :loading="loading">查询</el-button>
      </el-form-item>
    </el-form>

    <c-table
      border
      class="table-sm"
      v-loading="loading"
      :columns="tableColumns"
      :data="tableData"
    ></c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      params: {
        index: 1,
        size: 10,
      },
      loading: false,
      totalCount: 0,
      tableData: [],
      tableColumns: [
        { attrs: { label: '姓名', prop: 'real_name' } },
        { attrs: { label: '账号名称', prop: 'user_name' } },
        { attrs: { label: '电话号码', prop: 'phone_number' } },
        {
          attrs: { label: '操作', align: 'center', minWidth: '100' },
          operations: [
            {
              name: '重置密码',
              event: this.resetPassWord,
            },
          ],
        },
      ],
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  mounted() {},
  methods: {
    resetPassWord(row) {
      this.$utils
        .msgbox({
          message: `确认重置密码?`,
          type: 'info',
          beforeClose: () =>
            this.$http.put('/auth/user/reset/password/backstage/', { userId: row.user_id }),
        })
        .then(() => {
          this.$message.success('操作成功！')
          this.getData()
        })
        .catch(err => this.$message.error(`操作失败，请重试！${err.data}`))
    },
    getData() {
      this.loading = true
      this.$api
        .getData('credit', 'user_auth_view', this.params)
        .then(res => {
          const data = (res && res.data) || {}
          this.tableData = data.data || []
          this.totalCount = data.totalCount
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>

<style lang="scss" scoped></style>
